from event      import * 
from component  import *   
from simulator  import *  

class example1(Component):
	def __init__(self):
		super(example1,self).__init__("example1")
		self.e1 = Event("e1")
		self.thread1_handle=0
	
	def thread1(self):
		print "t1:b1"
		yield wait_time,10
		print "t1:b2"
		yield wait_time,100
		print "t1:b3"
	
	def thread2(self):
		while(True):
			print "t2:b1"
			self.e1.emit()
			yield wait_time,1
			print "t2:b2"
	
	def thread3(self,t2):
		for i in range(3):
			print "t3:b1"
			yield wait_event,e1
			print "t3:b2"
		self.kill_thread(t2)

	def run():
		self.start( self.thread1() )
		t2=self.start( self.thread2() )
		self.start( self.thread3(t2) )


sim = Simulator()
top = example1()
sim.simulate()

